#!/bin/bash

BASE_DIR="$(dirname $(realpath ${BASH_SOURCE}))"

export PROJECT_DIR=${BASE_DIR%/*/*}
CP="rsync -a"
#CP=cp
export PATH=/disk4T/code/T113/MYD/auto-t113-linux/out/t113/myir_nand/longan/buildroot/host/bin:${PATH}
export PATH=/opt/Qt5.12.10/5.12.10/gcc_64/bin:${PATH}

export CC=arm-linux-gnueabi-gcc
export STRIP=arm-linux-gnueabi-strip

QMAKE="qmake -spec linux-arm-t113-br-g++"
OUTDIR=$BASE_DIR/out

[ -d $OUTDIR ] || mkdir $OUTDIR

cd $OUTDIR 

$QMAKE $BASE_DIR/ssicloudLib.pro

make -j4
[ $? -ne 0 ] && {
    echo "make failed."
    exit 1
}

INSDIR=$OUTDIR/install
INCDIR=$INSDIR/include
LIBDIR=$INSDIR/lib

[ -d $INCDIR/events ] || mkdir -p $INCDIR/events    
[ -d $INCDIR/log ] || mkdir -p $INCDIR/log
[ -d $INCDIR/util ] || mkdir -p $INCDIR/util
[ -d $INCDIR/net_util ] || mkdir -p $INCDIR/net_util
[ -d $INCDIR/common_func ] || mkdir -p $INCDIR/common_func
[ -d $INCDIR/ssicloud ] || mkdir -p $INCDIR/ssicloud


$CP $PROJECT_DIR/corelib/events/*.h $INCDIR/events/ 
$CP $PROJECT_DIR/corelib/log/*.h    $INCDIR/log/
$CP $PROJECT_DIR/corelib/util/*.h   $INCDIR/util/ 
$CP $PROJECT_DIR/netLoad/net_util/*.h       $INCDIR/net_util/
$CP $PROJECT_DIR/netLoad/common_func/*.h    $INCDIR/common_func/
$CP $BASE_DIR/src/*.h    $INCDIR/ssicloud/
$CP $BASE_DIR/doc    $INSDIR/

$CP libssicloud.so  $LIBDIR/

cd - > /dev/null

cd $INSDIR/
tar -zcf ${BASE_DIR}/ssicloud.tar.gz *
cd - > /dev/null

